import os.path
from checkers import utils

class Logger:

    def __call__(self, player, game, state, move):
        utils.abstract()

class DisplayLogger(Logger):

    def __call__(self, player, game, state, move):
        game.display_move(move, state)

class FileLogger(Logger):

    def __init__(self, fp, take=False):
        self.fp = os.path.abspath(os.path.expanduser(fp))
        self.take = take

    def __call__(self, player, game, state, move):
        f = open(self.fp, 'ab+')
        msg = '%s:' % state.to_move
        current, dest, steps, taken = move
        if steps:
            for step in steps:
                msg += '%s%s-%s%s ' % (current[0], current[1],
                                       step[0], step[1])
                current = step
            if self.take:
                msg += ' X'
        else:
            msg += '%s%s-%s%s ' % (current[0], current[1], dest[0], dest[1])
        msg.strip()
        msg += '\n'
        f.write(msg)
        f.close()
